package server

import (
	"fmt"
	"google.golang.org/protobuf/types/known/anypb"
	pb "lht-go-plugins/internal/server/proto"
)

// 示例：地理插件
func (s *PluginServiceImpl) handleGeoSync(req *pb.CommonRequest) (*pb.CommonResponse, error) {
	switch req.Method {
	case "ConvertCoordinate":
		// 解析 ConvertCoordinateRequest
		var convertReq pb.ConvertCoordinateRequest
		if err := req.Payload.UnmarshalTo(&convertReq); err != nil {
			return &pb.CommonResponse{
				RequestId: req.RequestId,
				Code:      -1,
				Message:   "解析 ConvertCoordinateRequest 失败: " + err.Error(),
			}, nil
		}

		fmt.Println("坐标转换请求 =>", convertReq.Latitude, convertReq.Longitude, convertReq.TargetSystem)

		// TODO: 实际坐标转换逻辑
		data, _ := anypb.New(&pb.ConvertCoordinateResponse{
			Latitude:  30.1234,
			Longitude: 120.5678,
			System:    "WGS-84",
		})

		return &pb.CommonResponse{
			RequestId: req.RequestId,
			Code:      0,
			Message:   "坐标转换成功",
			Data:      data,
		}, nil
	}
	return &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      -1,
		Message:   "坐标转换失败",
	}, nil
}

// 示例：算法插件
func (s *PluginServiceImpl) handleAlgorithmSync(req *pb.CommonRequest) (*pb.CommonResponse, error) {
	fmt.Println("执行算法插件逻辑...")
	data, _ := anypb.New(&pb.CommonResponse{
		RequestId: req.RequestId,
		Message:   "算法执行完成",
	})
	return &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "算法成功执行",
		Data:      data,
	}, nil
}

// 示例：加解密插件
func (s *PluginServiceImpl) handleEncryptSync(req *pb.CommonRequest) (*pb.CommonResponse, error) {
	fmt.Println("执行加解密插件逻辑...")
	return &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "加解密操作完成",
	}, nil
}

// 示例：加解密插件
func (s *PluginServiceImpl) handleCacheSync(req *pb.CommonRequest) (*pb.CommonResponse, error) {
	fmt.Println("执行缓存插件逻辑...")
	return &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "缓存操作完成",
	}, nil
}

// 示例：加解密插件
func (s *PluginServiceImpl) handleDatabaseSync(req *pb.CommonRequest) (*pb.CommonResponse, error) {
	fmt.Println("执行数据库插件逻辑...")
	return &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "数据库操作完成",
	}, nil
}
